<template>
  <div id="app">
    <ul>
      <li v-for="(item,index) in arr" :key="index">
        <span>{{item}}</span>
        <button @click="delFn(index)">删除</button>
      </li>
    </ul>
    <button @click="btnFn">生成</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      arr: [1, 5, 3],
    };
  },
  methods: {
    btnFn(){
      // 生成0-50之间的随机数
      let num = Math.floor(Math.random()*50)
      // 将随机数追加到arr数组中
      this.arr.push(num)
    },
    // 形参
    delFn(a){
      this.arr.splice(a,1)
    }
  },
}
</script>